package com.ubis.ibms.plugin.dialogs;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.nebula.widgets.calendarcombo.CalendarCombo;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class TaskAddDialog extends Dialog {
	
	//名称
	private Text nameText;
	//所属部门
	private ComboViewer depComboViewer;
	private Combo depCombo;
	//工作描述
	private Text descriptionText;
	//考核标准
	private Text assessText;
	//提交
	private Button okButton;
	//清空
	private Button clearButton;
	
	private Composite container;
		
	/**
	 * Create the dialog.
	 * @param parentShell
	 */
	public TaskAddDialog(Shell parentShell) {
		super(parentShell);
	}

	/**
	 * Create contents of the dialog.
	 * @param parent
	 */
	@Override
	protected Control createDialogArea(Composite parent) {
		container = (Composite) super.createDialogArea(parent);
		GridLayout layout = new GridLayout(3, false);
		layout.marginWidth = 10;
		layout.marginHeight = 10;
		container.setLayout(layout);
		
		//名称
		Label nameLabel = new Label(container, SWT.RIGHT);
		nameLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		nameLabel.setText("工作名称：");
		nameText = new Text(container, SWT.BORDER);
		nameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		new Label(container, SWT.NONE);
		
		//所属部门
		Label depLabel = new Label(container, SWT.RIGHT);
		depLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false,
				false, 1, 1));
		depLabel.setText("所属部门：");
		depComboViewer = new ComboViewer(container, SWT.READ_ONLY);
		depCombo = depComboViewer.getCombo();
		depCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
				false, 1, 1));
		depComboViewer.setContentProvider(ArrayContentProvider
				.getInstance());
		depComboViewer.setLabelProvider(new LabelProvider() {
			@Override
			public String getText(Object element) {
				//TODO 得到部门text
//						if (element instanceof Building) {
//							Building building = (Building) element;
//							return building.getEms_name();
//						}
				return super.getText(element);
			}
		});
		// TODO 获取部门数据
		new Label(container, SWT.NONE);
//				List<Building> buildings = EstateManager.getBuildings();
//				buildingComboViewer.setInput(buildings);
//
//				buildingComboViewer
//						.addSelectionChangedListener(new ISelectionChangedListener() {
//							@Override
//							public void selectionChanged(SelectionChangedEvent event) {
//								IStructuredSelection selection = (IStructuredSelection) event
//										.getSelection();
//								long buildingId = ((Building) selection
//										.getFirstElement()).getId();
//								// 获取楼层数据
//								List<Floor> floors = EstateManager
//										.getFloorsByBuilding(buildingId);
//								floorComboViewer.setInput(floors);
//							}
//						});
		
		//工作描述
		Label descriptionLabel = new Label(container, SWT.RIGHT);
		descriptionLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		descriptionLabel.setText("工作描述：");
		descriptionText = new Text(container, SWT.BORDER);
		descriptionText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		new Label(container, SWT.NONE);
		
		//考核标准
		Label assessLabel = new Label(container, SWT.RIGHT);
		assessLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		assessLabel.setText("工作描述：");
		assessText = new Text(container, SWT.BORDER);
		assessText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		new Label(container, SWT.NONE);
		
		Composite btnComposite = new Composite(parent, SWT.NONE);
		btnComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false,
				1, 1));
		btnComposite.setLayout(new GridLayout(2, false));
		
		return container;
	}

	/**
	 * Create contents of the button bar.
	 * @param parent
	 */
	@Override
	protected void createButtonsForButtonBar(Composite parent) {
		parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
				false, 1, 1));
		parent.setLayout(new GridLayout(2, false));
		okButton = createButton(parent, IDialogConstants.CLIENT_ID, "添加",
				false);
		okButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true,
				false, 1, 1));
		okButton.addMouseListener(new MouseAdapter() {
			public void mouseUp(MouseEvent e) {
				// 点击添加时
			}
		});
		clearButton = createButton(parent, IDialogConstants.CLIENT_ID,
				"清空", false);
		clearButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true,
				false, 1, 1));
		clearButton.addMouseListener(new MouseAdapter() {
			public void mouseUp(MouseEvent e) {
				// 点击清空时
			}
		});
	}

	/**
	 * Return the initial size of the dialog.
	 */
	@Override
	protected Point getInitialSize() {
		return new Point(300, 300);
	}

	@Override
	protected void configureShell(Shell newShell) {
		super.configureShell(newShell);
		newShell.setText("员工登记");
	}

}
